<?php

function delete_sgpage($pids) {
	
	if(is_array($pids)) {
		$pids = dimplode($pids);
	}
	
	DB::delete('sgpage', "pid IN($pids)");

	$query = DB::query("SELECT * FROM ".DB::table('sgpage_attachment')." WHERE pid IN ($pids)");
	while ($value = DB::fetch($query)) {
		$attachment[] = $value;
		$attachdel[] = $value['attachid'];
	}
	
	foreach ($attachment as $value) {
		delete_attach($value['attachment'], 'sgpage', $value['thumb'], $value['remote']);
	}
	DB::delete('sgpage_attachment', "pid IN ($pids)");
	
}

?>